package com.jdk.demo.fileChannel.openfile;

import java.io.File;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

public class Delete {

	// 会尽最大努力尝试在关闭时通过适当的close方法删除该文件。如果未调用close方法，则在java虚拟机终止时尝试删除文件
	public static void main(String[] args) throws Exception {
		File file = new File("r.txt");
		Path path = file.toPath();
		FileChannel fileChannel = FileChannel.open(path, StandardOpenOption.DELETE_ON_CLOSE, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
		Thread.sleep(10000);
		fileChannel.close();
	}
	// 先创建文件，然后程序结束后删除
	
}
